/*
 * @Author: wangzhichiao<https://github.com/wzc570738205>
 * @Date: 2020-05-25 09:07:34
 * @LastEditors: wangzhichiao<https://github.com/wzc570738205>
 * @LastEditTime: 2020-05-25 09:19:39
 */
import Router from 'vue-router'

function importAll(routerArr) {
  routerArr.keys().forEach(item => routerList.push(routerArr(item).default))
}

export const routerList = []

importAll(require.context('./module', false, /\.routes\.js/))

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '*',
      redirect: '/index/dashboard'
    },
    {
      path: '/login',
      component: () => import('../pages/login'),
      meta: {
        ignore: true
      }
    },
    ...routerList
  ]
})

router.beforeEach((to, _from, next) => {
  next()

  // 判断是否需要登录认证
/*   if (!to.meta.ignore) {
    const authInfo = getAuthInfo()
    // 判断是否存在认证信息
    if (authInfo) {
      next()
    } else {
      next({
        path: '/login'
      })
    }
  } else {
    next()
  } */
})

export default router
